home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1997 / MacHack 1997.toast / Hacks / Hacks ’97 / Warrior’s Progress / source code / Source / Libraries / Memory / AlignedBlock.h < prev    next >
Encoding:
Text File  |  1997-06-28  |  653 b   |  34 lines  |  [TEXT/CWIE]

  1. // AlignedBlock.h
  2.  
  3. #ifndef AlignedBlock_h
  4. #define AlignedBlock_h
  5.  
  6. #ifndef Integers_h
  7. #include "Integers.h"
  8. #endif
  9.  
  10. template < uint32 size >
  11. class AlignedBlock
  12.   {
  13.     typedef uint32 Unit;        // Set this to the hardest-to-align type
  14.     
  15.     private:
  16.         Unit space[ (size + sizeof(Unit) - 1) / sizeof(Unit) ];
  17.     
  18.     public:
  19.         void *operator[]( uint32 position )
  20.           {
  21.             return reinterpret_cast<uint8 *>( space ) + position;
  22.           }
  23.         
  24.         const void *operator[]( uint32 position ) const
  25.           {
  26.             return reinterpret_cast<const uint8 *>( space ) + position;
  27.           }
  28.         
  29.         operator const void *() const        { return space; }
  30.         operator void *()                        { return space; }
  31.   };
  32.  
  33. #endif
  34.